# -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
#    $Id$
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields,osv
from osv.orm import except_orm
import tools
import pytz
from tools.translate import _

class account_payment_term_line(osv.osv):
    _name = "account.payment.term.line"
    _description = "Payment Term Line"
    _inherit="account.payment.term.line"
    
#    def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=80):
#        if not args:
#            args=[]
#        if not context:
#            context={}
#        ids = self.search(cr, user,args, limit=limit, context=context)
#        if name:
#            ids = self.search(cr, user, [('login','=',name)]+ args, limit=limit)
#        if not ids:
#            ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit)
#        return self.name_get(cr, user, ids)    

    def search(self, cr, user, args, offset=0, limit=None, order=None,  context=None, count=False):
        if context:
            if 'project_id' in context.keys():
                cr.execute("Select \
                                id \
                            from \
                                account_payment_term_line\
                            where \
                                payment_id=(Select payment_term from account_analytic_account where id=%s)" % context['project_id'])
                res = cr.fetchall()
                res1=[]
                for tmp in res:
                    res1.append(tmp[0])
                var_filter=res1
                args.append(('id','in',var_filter))
    #                return var_filter
                context=None
            #raise osv.except_osv(_('Invalid action !'),_('Cannot delete Request(s) which are in (%s) State1!' %args))

           # args.append
        return super(account_payment_term_line,self).search(cr, user, args, offset, limit, order=order,context=context, count= count)
account_payment_term_line()

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: